package cn.ytnet.shangyun.service.basic.rest.controller;

import cn.ytnet.shangyun.service.basic.entity.ProvinceEntity;
import cn.ytnet.shangyun.service.basic.service.ProvinceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by cyongk on 2016/1/8.
 */
@RestController
@RequestMapping("/rest")
public class ProvinceController {


    private ProvinceService provinceService;

    public ProvinceService getProvinceService() {
        return provinceService;
    }

    @Resource
    public void setProvinceService(ProvinceService provinceService) {
        this.provinceService = provinceService;
    }

    //单个保存
    @RequestMapping(value = "/province",method = RequestMethod.POST)
    public void save(@RequestBody ProvinceEntity provinceEntity){
        System.out.println("编号：" + provinceEntity.getPkTProvinceId() +
                " 名称： " + provinceEntity.getProvinceName() +
                " 拼音：" + provinceEntity.getProvincetPhoneticcode());
        provinceService.saveProvince(provinceEntity);
    }

    //查询全部
    @RequestMapping(value = "/province",method = RequestMethod.GET)
    public List<ProvinceEntity> findAll(){
        return provinceService.findAllProvince();
    }

    /*//查询单个
    @RequestMapping(value = "/users/{id}",method = RequestMethod.GET)
    public User get(@PathVariable("id") int id){
        return userDAO.find(id);
    }*/

    //单个更新
    @RequestMapping(value = "/province/{id}",method = RequestMethod.PUT)
    public void update(@PathVariable("id") String id,@RequestBody ProvinceEntity provinceEntity){
        provinceService.updateProvince(id, provinceEntity);
    }

    /*//单个删除
    @RequestMapping(value = "/users/{id}",method = RequestMethod.DELETE)
    public ResponseEntity<Boolean> delete(@PathVariable("id") int id){
        userDAO.delete(id);
        return new ResponseEntity<Boolean>(Boolean.TRUE, HttpStatus.OK);
    }*/
}
